﻿/**********************************************************
*
* 模块名称：WebDemo编辑页面
* 当前版本：1.0
* 添加人员：楚涛
* 开始时间：2010-10-10
* 版本历史：v1.0
*
***********************************************************/
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using LXChuTao.ECG.Demo.Entity;
using LXChuTao.ECG.Demo.WebUI;

public partial class Form_WebDemoEdit : LXChuTao.ECG.Demo.WebUI.BasePage
{
    #region 私有变量
    /// <summary>
    /// 流水号
    /// </summary>
    private string p_c_id
    {
        set { ViewState["p_c_id"] = value; }
        get { return ViewState["p_c_id"].ToString(); }
    }
    #endregion

    /// <summary>
    /// 页面载入
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            try
            {
                this.Response.CacheControl = "no-cache";
                if (Request.QueryString["CMD"] == "Edit" && !string.IsNullOrEmpty(Request.QueryString["p_c_id"]))
                {
                    p_c_id = Request.QueryString["p_c_id"];
                    BindPage(p_c_id);
                }
                else
                {
                    p_c_id = WebFunHelper.GetKeyId;
                }
            }
            catch (Exception ex)
            {
                WebFunHelper.ShowMessage(this, "页面载入异常：" + ex.Message);
            }
        }
    }

    #region 页面事件
    /// <summary>
    /// 保存事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnSave_Click(object sender, EventArgs e)
    {
        T_DEMO entity = new T_DEMO();
        entity.C_ID = p_c_id;
        entity.C_NAME = this.txtName.Text;
        entity.C_IDCARD = this.txtIDCard.Text;
        entity.C_STRING = this.txtString.Text;
        entity.C_STRINGA = this.txtStringA.Text;
        entity.C_STRINGB = this.txtStringB.Text;
        entity.C_EMAIL = this.txtEMail.Text;
        entity.C_EIDTDATE = DateTime.Now;
        try
        {
            if (!string.IsNullOrEmpty(this.txtDate.Text))
                entity.C_DATE = Convert.ToDateTime(this.txtDate.Text);
            if (!string.IsNullOrEmpty(this.txtInt.Text))
                entity.C_INT = Convert.ToInt32(this.txtInt.Text);
            if (!string.IsNullOrEmpty(this.txtIntA.Text))
                entity.C_INTA = int.Parse(this.txtIntA.Text);
            if (!string.IsNullOrEmpty(this.txtIntB.Text))
                entity.C_INTB = int.Parse(this.txtIntB.Text);
            if (!string.IsNullOrEmpty(this.txtFloat.Text))
                entity.C_FLOAT = float.Parse(this.txtFloat.Text);
            if (!string.IsNullOrEmpty(this.txtFloatA.Text))
                entity.C_FLOATA = float.Parse(this.txtFloatA.Text);
            if (!string.IsNullOrEmpty(this.txtFloatB.Text))
                entity.C_FLOATB = float.Parse(this.txtFloatB.Text);
            DateTime dt1 = DateTime.Now;
            if (entity.SaveEx() > 0)
            {
                DateTime dt2 = DateTime.Now;
                if (Request.QueryString["CMD"] == "Add")
                {
                    this.btnCreate.Visible = true;
                }
                this.hidSave.Value = "1";//标示已经录入信息
                WebFunHelper.ShowMessage(this, "保存成功");
            }
            else
            {
                WebFunHelper.ShowMessage(this, "保存失败");
            }
        }
        catch (Exception ex)
        {
            WebFunHelper.ShowMessage(this, "保存异常：" + ex.Message);
        }
    }
    /// <summary>
    /// 再写一条事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnCreate_Click(object sender, EventArgs e)
    {
        p_c_id = WebFunHelper.GetKeyId;
        this.txtName.Text = "";
        this.txtIDCard.Text = "";
        this.txtDate.Text = "";
        this.txtString.Text = "";
        this.txtStringA.Text = "";
        this.txtStringB.Text = "";
        this.txtEMail.Text = "";
        this.txtInt.Text = "";
        this.txtIntA.Text = "";
        this.txtIntB.Text = "";
        this.txtFloat.Text = "";
        this.txtFloatA.Text = "";
        this.txtFloatB.Text = "";
    }
    #endregion

    #region 页面方法
    /// <summary>
    /// 绑定页面控件信息
    /// </summary>
    /// <param name="c_id"></param>
    private void BindPage(string c_id)
    {
        T_DEMO entity = new T_DEMO(c_id);
        this.txtName.Text = entity.C_NAME;
        this.txtIDCard.Text = entity.C_IDCARD;
        this.txtDate.Text = entity.C_DATE != DateTime.MinValue ? entity.C_DATE.ToShortDateString() : "";
        this.txtString.Text = entity.C_STRING;
        this.txtStringA.Text = entity.C_STRINGA;
        this.txtStringB.Text = entity.C_STRINGB;
        this.txtEMail.Text = entity.C_EMAIL;
        this.txtInt.Text = entity.C_INT != int.MinValue ? entity.C_INT.ToString() : "";
        this.txtIntA.Text = entity.C_INTA != int.MinValue ? entity.C_INTA.ToString() : "";
        this.txtIntB.Text = entity.C_INTB != int.MinValue ? entity.C_INTB.ToString() : "";
        this.txtFloat.Text = entity.C_FLOAT != float.MinValue ? entity.C_FLOAT.ToString() : "";
        this.txtFloatA.Text = entity.C_FLOATA != float.MinValue ? entity.C_FLOATA.ToString() : "";
        this.txtFloatB.Text =entity.C_FLOATB != float.MinValue ?  entity.C_FLOATB.ToString() : "";
    }
    #endregion
}
